/*
 * Copyright (C) 2012-2013 Michael L.R. Marques
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 * 
 * Contact: michaellrmarques@gmail.com
 */
package com.jm.jmsql.database;

import com.jm.commons.ui.UIBounds;
import com.jm.jmsql.models.JMSqlObjectTableModel;
import com.jm.jmsql.objects.base.JMSqlObject;
import java.awt.Frame;

/**
 *
 * @author Michael L.R. Marques
 */
public class Properties extends javax.swing.JDialog {

    /**
     * Creates new form Properties
     */
    private Properties(Frame parent, JMSqlObject object) {
        super(parent);
        initComponents();
        this.mainPanel.setImage(new java.io.File("./images/optionslogo.png"));
        UIBounds.setBounds(parent, this);
        setTitle(object.getObjectType().toString() + " Properties");
        this.lblProperties.setText(object.getProperties());
        if (!object.isEmpty()) {
            this.tableChildren.setModel(new JMSqlObjectTableModel(object));
            pack();
        } else {
            this.scrollTableChildren.setVisible(false);
            pack();
            setSize(getWidth(), getHeight() + 25);
        }
    }
    
    /**
     * 
     * @param object 
     */
    public static void showDialog(JMSqlObject object) {
        showDialog(null, object);
    }
    
    /**
     * 
     * @param parent
     * @param object 
     */
    public static void showDialog(Frame parent, JMSqlObject object) {
        Properties properties = new Properties(parent, object);
        properties.setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new com.jm.commons.components.panel.ImagePanel();
        lblProperties = new javax.swing.JLabel();
        scrollTableChildren = new javax.swing.JScrollPane();
        tableChildren = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Properties");
        setLocationByPlatform(true);
        setMinimumSize(new java.awt.Dimension(100, 100));
        setModal(true);

        mainPanel.setImage(new java.io.File("C:\\Users\\Michael\\Documents\\NetBeansProjects\\JMSql\\images\\optionslogo.png"));

        lblProperties.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        lblProperties.setText("Properties Information");

        tableChildren.setAutoCreateRowSorter(true);
        tableChildren.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        tableChildren.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        tableChildren.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        scrollTableChildren.setViewportView(tableChildren);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(scrollTableChildren, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(lblProperties, javax.swing.GroupLayout.DEFAULT_SIZE, 365, Short.MAX_VALUE)))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(88, 88, 88)
                .addComponent(lblProperties)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scrollTableChildren, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel lblProperties;
    private com.jm.commons.components.panel.ImagePanel mainPanel;
    private javax.swing.JScrollPane scrollTableChildren;
    private javax.swing.JTable tableChildren;
    // End of variables declaration//GEN-END:variables
}
